//
//  RegisterViewController.m
//  TheRoadAD
//
//  Created by baixue on 16/8/5.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "RegisterViewController.h"

@interface RegisterViewController ()
@property (weak, nonatomic) IBOutlet UITextField *Password;//密码
@property (weak, nonatomic) IBOutlet UITextField *UserName;//用户名//手机号
@property (weak, nonatomic) IBOutlet UILabel *registerTitle;

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _registerTitle.font = [UIFont fontWithName:@"qingyuan" size:19.0f];
}

//返回按钮 返回登录页面
- (IBAction)backItem:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

//获取验证码
- (IBAction)getVerificationCode:(id)sender {
}

//注册 注册成功返回登录页面
- (IBAction)registerBtn:(id)sender {
   
    if ([_UserName.text isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入手机号" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
//    else if (_UserName.text.length < 6) {
//        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//        [alert show];
//    }
    else if ([_Password.text isEqualToString:@""]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入密码" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }else if (_Password.text.length < 6) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"密码不能少于6位" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }else{
        [self setRegister];
    }
    
    
    
}

//注册请求
-(void)setRegister{
//    http://114.215.172.41:7756/UserInfo/ResUser

    /**
     *  userName  用户名
     *  passWord  密码
     */
    NSString *key = [SHA1Secret getKeyWithActionName:@"ResUser"];
    NSDictionary *para = @{
                           @"UserName":_UserName.text,
                           @"Password":_Password.text,
                           @"Key":key
                           };
    [NetWorkManager requestWithType:HttpRequestTypePost withUrlString:@"UserInfo/ResUser" withParaments:para withSuccessBlock:^(NSDictionary *object) {
        if ([object[@"code"] isEqualToString:@"100"]) {
            [self dismissViewControllerAnimated:YES completion:nil];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:object[@"message"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
        }
        
    } withFailureBlock:^(NSError *error) {
        NSLog(@"%@",error);
    } progress:nil];
    
   
}
//空白收键盘
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

@end
